$(function () {
	// 获取id
	$(document).ready(function () {
		mui.showLoading("正在加载..", "div");

		var map = new BMapGL.Map("container");
		map.enableScrollWheelZoom();




		// setMap();
		getData();


		function getData() {
			var Request = new Object();
			Request = GetRequest();
			var plateNo = decodeURIComponent(Request["plateNo"]);
			var x = decodeURIComponent(Request["x"]);
			var y = decodeURIComponent(Request["y"]);
			ajax(getWaybillMapDetail_url, {
				plateNo: plateNo
			}, "GET", function (res) {
				if (res.code == 200) {
					if (res.data) {
						let data = res.data;
						$(".corpCarLimit").html(data.corpCarLimit)
						$(".corpCarExist").html(data.corpCarExist)
						$(".corpCarSurplus").html(data.corpCarSurplus)
						if (data.dangerMsg == undefined || data.dangerMsg == '') {
							$(".info").attr("style", "display:none;");
						} else {
							$(".info").html(data.dangerMsg);
							$(".info").attr("style", "display:block;");
						}
						mui.hideLoading();
						var p1 = new BMapGL.Point(x, y);
						var p2 = new BMapGL.Point(data.corpLocation.x, data.corpLocation.y);
						var driving = new BMapGL.DrivingRoute(map, {
							renderOptions: {
								map: map,
								autoViewport: true
							}
						});
						driving.search(p1, p2);

						var opts = {
							position: new BMapGL.Point(data.corpLocation.x, data.corpLocation.y), // 指定文本标注所在的地理位置
							offset: new BMapGL.Size(20, -30) // 设置文本偏移量
						};
						// 创建文本标注对象
						var label = new BMapGL.Label(data.startAddress, opts);
						// 自定义文本标注样式
						label.setStyle({
							color: '#000000',
							borderRadius: '5px',
							boxShadow: ' 0 2px 6px 0 rgb(27 142 236 / 50%)',
							borderColor: '#ccc',
							padding: '0 10px',
							fontSize: '16px',
							height: '30px',
							lineHeight: '30px',
							fontFamily: '微软雅黑'
						});
						map.addOverlay(label);
						let corpFenceList = data.corpFenceList;
						for (var j = 0; j < corpFenceList.length; j++) {
							let pointList = data.corpFenceList[j].pointList;
							var pintListData = JSON.parse(pointList);
							let pointStr = pintListData.toString();
							// let pintListData = [];
							// for (var i = 0; i < pointList.length; i++) {
							// 	pintListData.push(new BMapGL.Point(pointList[i].x, pointList[i].y))
							// }
							// 创建多边形
							var polygon = new BMapGL.Polygon(pintListData, {
								strokeColor: 'red',
								fillColor: "red",
								fillOpacity: 0.4,
								strokeWeight: 2,
								strokeOpacity: 0.5
							});
							map.addOverlay(polygon);
							
							let firstPoint = pointStr.split(';')[0];
							let resutFirstPoint = firstPoint.split(',');
							var opts = {
								position: new BMapGL.Point(resutFirstPoint[0],resutFirstPoint[1]), // 指定文本标注所在的地理位置
								offset: new BMapGL.Size(20, -30) // 设置文本偏移量
							};
							var nameInfo = data.corpFenceList[j].fenceName + ',容纳量:' + data.corpFenceList[j].fenceCarLimit
							// 创建文本标注对象
							var label = new BMapGL.Label(nameInfo, opts);
							// 自定义文本标注样式
							label.setStyle({
								color: '#000000',
								borderRadius: '5px',
								boxShadow: ' 0 2px 6px 0 rgb(27 142 236 / 50%)',
								borderColor: '#ccc',
								padding: '0 10px',
								fontSize: '16px',
								height: '30px',
								lineHeight: '30px',
								fontFamily: '微软雅黑'
							});
							map.addOverlay(label);

						}


					}

				} else {
					map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12);
					// mui.toast(res.msg);
					mui.hideLoading();

				}
			});
		}



		// 查询全部车辆
		// ajax(getCarsByOwnerId_url, {}, "GET", function (res) {
		// 	mui.hideLoading();
		// 	if (res.status == 200) {
		// 		let data = res.data;
		// 		if (data) {
		// 			$(".all").text(data.allCar ? data.allCar : '0');
		// 			$(".sign").text(data.signInCar ? data.signInCar : '0');
		// 			$(".task").text(data.taskCar ? data.taskCar : '0');
		// 			let carInfoData = data.gpsInfoList;
		// 			if (carInfoData) {
		// 				for (var i = 0; i < carInfoData.length; i++) {
		// 					var onlineStatus = carInfoData[i].online;
		// 					// 车辆未绑定射别的状态下，无法查看到车辆信息
		// 					if (carInfoData[i].longitude && carInfoData[i].latitude) {
		// 						marker = new AMap.Marker({
		// 							autoRotation: true,
		// 							angle: carInfoData[i].direction - 90,
		// 							position: [carInfoData[i].longitude, carInfoData[i].latitude],
		// 						});
		// 						if (onlineStatus == "1") {
		// 							marker.setIcon("img/online.png");
		// 							carStatusInfo = '在线';
		// 						} else if (onlineStatus == "2") {
		// 							marker.setIcon("img/parkcar.png");
		// 							carStatusInfo = '停车';
		// 						} else if (onlineStatus == "3") {
		// 							marker.setIcon("img/outline.png");
		// 							carStatusInfo = '离线';
		// 						} else if (onlineStatus == "4") {
		// 							marker.setIcon("img/weakSignals.png");
		// 							carStatusInfo = '信号弱';
		// 						}
		// 						// 点击mark点回显得内容
		// 						marker.infoName = carInfoData[i].carNumber;
		// 						marker.carId = carInfoData[i].carId;
		// 						marker.carStatusInfo = carStatusInfo;
		// 						marker.lon = carInfoData[i].longitude;
		// 						marker.lat = carInfoData[i].latitude;
		// 						marker.on('click', function (e) {
		// 							slideInfo(e.target);
		// 							gothere(e.target)
		// 							$(".closeBtn").on('click', function () {
		// 								$(".info-content").hide();
		// 							});
		// 						});
		// 						marker.setLabel({
		// 							offset: new AMap.Pixel(5, 15),
		// 							content: `<div class='info-con'>${carInfoData[i].carNumber}</div>`, //设置文本标注内容
		// 							direction: 'right' //设置文本标注方位
		// 						});
		// 						markerList.push(marker);
		// 						marker.setMap(map);
		// 						map.setFitView();
		// 					}
		// 				}
		// 			}
		// 		}
		// 	} else {
		// 		mui.toast(res.message)
		// 	}
		// });
		// 刷新
		$(".refresh").on("tap", function () {

		});
		// 关闭
		$(".closeBtn").on('tap', function () {
			$(".info-content").hide();
		});




	});
});